<script type="text/javascript">
var uploader = WebUploader.create({
        swf: '/admin/lib/webuploader/0.1.5/Uploader.swf',
		server: '/guidance_service/front/data/individual/input.do?costId='+GetQueryString('costId'),  // 文件接收服务端。
        auto : true,
        pick : "#input",
        resize : false,
        chunked: true
});

var loadingIndex;
uploader.on("uploadProgress",function(){
	loadingIndex = layer.load(1, {shade: [0.5,'#fff'] });//0.1透明度的白色背景
}).on("uploadComplete",function(){
	layer.close(loadingIndex);
});
uploader.on( 'uploadSuccess', function( file,response) {
//	if(response.resultCode == 400){
//		confirmInput(response)
//	}else 
    if(response.resultCode == 200){
		confirmData(response);
	}else{
		layer.msg(response.message,{icon:2,time:3000},function(){
			location.replace(location.href);
		});
	}
});
uploader.on( 'uploadError', function( file ) {  //上传失败
	layer.msg('导入失败',{icon:2,time:3000},function(){
			location.replace(location.href);
	});
});

//function confirmInput(response){
//	open(response.data.toString().replace(new RegExp(/(是否导入,)/g),"是否导入<br/>"),
//		function(index, layero){
//	  	   $.post("/guidance_service/front/data/info/confirmInput.do",{"UUID":response.ext,"costId":GetQueryString('costId')},function(reslut){
//	  	   	    if(reslut.resultCode == 200){
//	  	   	    	confirmGuidance(reslut);
//	  	   	    }else{
//	  	   	    	layer.msg('导入失败',{icon:2,time:3000},function(){
//						location.replace(location.href);
//					});
//	  	   	    }
//	  	   });
//	  	layer.close(index);
//	 });
//}
function confirmData(response){
	var fileName  = response.data.fileName;
	var html=fileName+"导入的表有：<br/>";
	delete  response.data.fileName;
	$.each(response.data,function(key,value){
		html+= (key+" : "+value+" 条数据 <br/>");
	});
	open(html,function(index, layero){
	  	   $.post("/guidance_service/front/data/individual/confirmInput.do",{"UUID":response.ext,"costId":GetQueryString('costId'),"individualName":fileName.split(".")[0]},function(reslut){
	  	   		if(reslut.resultCode == 200){
	  	   	    	layer.msg(reslut.message,{icon:1,time:3000},function(){
						location.replace(location.href);
					});
	  	   		}else{
		  	       	layer.msg('导入失败',{icon:2,time:3000},function(){
						location.replace(location.href);
					});
  	   	    	}
	  	   });
	  	   layer.close(index);
	});
}

function open(content,yes){
	layer.open({  //页面层
	  type: 1,
	  title:"等待确认：",
	  skin: 'layui-layer-rim', //加上边框
	  area: ['420px', '420px'], //宽高
	  content:content,
	  btn: ['确认导入', '取消导入'],
	  yes: yes 
	});
}
</script> 
